<!doctype html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<link rel="stylesheet" href="../res/css/weui.css"/>
<link rel="stylesheet" href="../res/css/weuix.css"/>
<script src="../res/js/zepto.min.js"></script>
<script src="../res/js/zepto.weui.js"></script>
<script src="../res/js/common.js?v=5"></script>

<script>
    var patientList;
    var inquiry_patient_id, inquiry_patient_img, inquiry_curr_date;

    function showUser() {
        var paramJson = { "phone": $('#txtCxPhone').val(), "user_id": user_id, "user_type": user_type, "rand": Math.random() };
        ajaxPostH("userSide_personal_inquiry_getPatientInfo", paramJson, showUserSuccess);
        return false;
    }

    function showUserSuccess(jsonInfo) {
        $('#txtCxPhone').blur();
        var jsonData = strToJson(jsonInfo);
        if (jsonData.code == '200') {
            patientList = jsonData.data.patientList; //患者列表
            var patientListData = '';
            var patNums;
            if (patientList.length > 0) {
                patNums = patientList.length;
                if (patNums > 50)
                    patNums = 50;
                for (var i = 0; i < patNums; i++) {
                    patientListData += '<tr onclick="patientListActive(' + i + ');">';
                    patientListData += '<td>' + patientList[i].inquiry_patient_name + '</td>';
                    patientListData += '<td>' + (patientList[i].inquiry_patient_sex == '1' ? "女" : "男") + '</td>';
                    patientListData += '<td>' + patientList[i].inquiry_patient_phone + '</td>';
					patientListData += '<td><span class="sel">选择<span></td>';
                    patientListData += '</tr>';
                }
                $('#userList').html(patientListData);
                $('#province').show();
            }
            else {
                msgInfo('该手机号没有历史记录');
                $('#province').hide();
            }
        }
        else
            msgInfo(jsonData.info);
    }

    function patientListActive(z) {
        inquiry_patient_id = patientList[z].inquiry_patient_id;
        inquiry_patient_img = patientList[z].inquiry_patient_img;
        $('#ddl_patient_type').val(patientList[z].inquiry_patient_type); //问诊类型
        $('#txt_patient_name').val(patientList[z].inquiry_patient_name); //姓名
        $('#txt_patient_phone').val(patientList[z].inquiry_patient_phone); //手机号码
        $('#txt_idno').val(patientList[z].inquiry_patient_idcard); //身份证号
        $('#ddl_sex_code').val(patientList[z].inquiry_patient_sex); //性别 0男 1女
        $('#txt_birthday').val(patientList[z].inquiry_patient_birthday); //出生日期
        $('#ddl_married').val(patientList[z].is_married); //是否已婚 0否 1是
        $('#txt_patient_jg').val(patientList[z].inquiry_patient_marital_status); //籍贯
        $('#ddl_patient_profession').val(patientList[z].inquiry_patient_profession); //职业
        $('#txt_patient_weight').val(patientList[z].inquiry_patient_weight); //体重
        $('#txt_address').val(patientList[z].inquiry_patient_address); //住址
        $('#ddl_drug_allergy').val(patientList[z].is_drug_allergy); //是否药物过敏 .0否 1是
        $('#txt_allergy_details').val(patientList[z].iinquiry_patient_allergy_details); //药物过敏史
        setDrugAllergy(patientList[z].is_drug_allergy);
        $('#province').hide();
    }

    function setDrugAllergy(is_drug_allergy) {
        //是否药物过敏 .0否 1是
        if (is_drug_allergy == '1')
            $('#div_allergy_details').show();
        else
            $('#div_allergy_details').hide();
    }

    function doSavePat() {
        var inquiry_patient_name, inquiry_patient_phone, inquiry_patient_idcard, inquiry_patient_birthday, inquiry_patient_weight, log_source;
        inquiry_patient_name = $('#txt_patient_name').val();
        if (isEmpty(inquiry_patient_name)) {
            msgInfo('请输入姓名');
            return;
        }
        inquiry_patient_phone = $('#txt_patient_phone').val();
        if (isEmpty(inquiry_patient_phone)) {
            msgInfo('请输入手机号');
            return;
        }
        else if (!IsPhone(inquiry_patient_phone)) {
            msgInfo('请输入正确的手机号');
            return;
        }
        inquiry_patient_idcard = $('#txt_idno').val();
        if (isEmpty(inquiry_patient_idcard)) {
            msgInfo('请输入身份证号');
            return;
        }
        inquiry_patient_birthday = $('#txt_birthday').val();
        if (isEmpty(inquiry_patient_birthday)) {
            msgInfo('请输入出生日期');
            return;
        }
        if (!$('#weuiAgree').attr('checked')) {
            msgInfo('请先了解并勾选协议');
            return;
        }
        inquiry_patient_weight = $('#txt_patient_weight').val();
        if (isEmpty(inquiry_patient_weight))
            inquiry_patient_weight = 0;
        if (isUndefinedAndEmpty(hospital_id))
            hospital_id = getUserInfo().hospital_id;
        log_source = (user_type == 1 ? '个人' : getUserInfo().store_name);
        localStorage.setItem("user_name_" + user_id, inquiry_patient_name);
        var paramJson = {
            "inquiry_patient_id": inquiry_patient_id, //患者id
            "hospital_id": hospital_id, //	医院id
            "user_type": user_type, //用户类型 1用户 2门店
            "user_id": user_id, //用户ID
            "inquiry_patient_type": $('#ddl_patient_type').val(), //问诊类型 0为自己问诊 1为他人问诊
            "inquiry_patient_img": inquiry_patient_img, //头像
            "inquiry_patient_name": inquiry_patient_name, //姓名
            "inquiry_patient_idcard": inquiry_patient_idcard, //身份证
            "inquiry_patient_sex": $('#ddl_sex_code').val(), //性别 0男 1女
            "inquiry_patient_birthday": inquiry_patient_birthday, //出生日期 1995-08-01
            "inquiry_patient_phone": inquiry_patient_phone, //手机号
            "is_married":  $('#ddl_married').val(), //是否已婚 0否 1是
            "inquiry_patient_marital_status":  $('#txt_patient_jg').val(), //籍贯
            "inquiry_patient_weight": inquiry_patient_weight, //体重
            "inquiry_patient_profession_code": $('#ddl_patient_profession').val(), //职业
            "inquiry_patient_profession": $('#ddl_patient_profession').find("option:selected").text(), //职业
            "inquiry_patient_address": $('#txt_address').val(), //住址
            "is_drug_allergy": $('#ddl_drug_allergy').val(), //是否药物过敏 .0否 1是
            "iinquiry_patient_allergy_details": $('#txt_allergy_details').val(), //药物过敏史
            "doctor_id": getQst('doctor_id'), //医生id
            "log_source": log_source, //个人/门店名称
            "log_type": getQst('log_type')//记录类型 1视频问诊 2图文问诊
        }
        ajaxPost("userSide_personal_inquiry_addInquiryPatientInfo", paramJson, doSavePatSuccess);
    }

    function doSavePatSuccess(jsonInfo) {
        if (jsonInfo.code == '200') {
            var data = jsonInfo.data;
			var hospital_id = getQst("hospital_id");
            goPage('chat.htm?isChatWait=1&log_id=' + data.log_id + '&doctor_id=' + data.doctor_id + '&log_type=' + data.log_type+ '&hospital_id=' + hospital_id);
            //window.location = path_url + 'util_toUserInterrogation.do?log_id=' + data.log_id + '&doctor_id=' + data.doctor_id + '&log_type=' + data.log_type
        }
        else
            msgInfo(jsonInfo.info);
    }

    function range(r, a, N) { var i, o, s = [], e = N || 1, f = !1; if (isNaN(r) || isNaN(a) ? isNaN(r) && isNaN(a) ? (f = !0, i = r.charCodeAt(0), o = a.charCodeAt(0)) : (i = isNaN(r) ? 0 : r, o = isNaN(a) ? 0 : a) : (i = r, o = a), !(i > o)) for (; i <= o; ) s.push(f ? String.fromCharCode(i) : i), i += e; else for (; i >= o; ) s.push(f ? String.fromCharCode(i) : i), i -= e; return s }

    function showAgreeInfo() {
        doGetAgree();
        $("#divAgreeInfo").popup(); //打开
    }

    function doGetAgree() {
        if (isEmpty($("#argeeTitle").text())) {
            var paramJson = { "init_id": '102', "rand": Math.random() };
            ajaxPost("util_getUtilInitData", paramJson, doGetAgreeOk);
        }
        return false;
    }

    function doGetAgreeOk(jsonInfo) {
        $("#argeeTitle").text(jsonInfo.data.init_name);
        $("#argeeContent").html(jsonInfo.data.init_key);
    }

    $(function () {
        inquiry_patient_id = "";
        inquiry_patient_img = "";
        checkLogin();
        $('#div_allergy_details').hide();
        $('#ddl_drug_allergy').on('change', function () {
            setDrugAllergy($(this).val());
        });
        $("#txt_idno").on('blur', function () {
            checkidno(document.getElementById('txt_idno'), document.getElementById('txt_birthday'), document.getElementById('ddl_sex_code'));
        });

        $("#txt_birthday").attr("max", getCurrDate());

        //就诊人列表
        $('#showuser').click(function () {
            showUser();
        });

        //立即咨询
        $('#btnInquiry').click(function () {
            doSavePat();
        });

        //返回上页
        $('#btnBack').on("click", function () {
            goPageNo(-1);
        });
		
    });
</script>
<style>
body{background-color:#EFF3F4}
.weui-header-fixed-top{border-bottom:1px solid #e8e8e8; left:0; top:0; right:0; z-index: 1; background:#F6F6F9}
.weui-flex{padding: 0.625rem;}
.weui-cells {margin-top: 0px;}
.weui-form__opr-area{margin: 0 auto; width: 80%;}

.choice{
	position: relative;
}
.choice .radio{
	position: relative;
	display: inline-block;
	font-weight: 400;
	color: #0c4757;
	padding-left: 25px;
	cursor: pointer;
}
.choice .radio input{
	position: absolute;
	left: -9999px;
}
.choice .radio i{
	display: block;
	position: absolute;
	top: 6px;
	left: 0;
	width: 15px;
	height: 15px;
	outline: 0;
	border: 1px solid #19BA86;
	border-radius: 50%;
	transition: border-color .3s;
	-webkit-transition: border-color .3s;
}
.choice .radio input:checked+i{
	border-color: #19BA86;
}
.choice .radio input+i:after{
	position: absolute;
	content: '';
	top: 3px;
	left: 3px;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background-color: #19BA86;
	opacity: 0;
	transition: opacity .1s;
	-webkit-transition: opacity .1s;
}
.choice .radio input:checked+i:after{
	opacity: 1;
}

</style>
</head>

<body ontouchstart>
    <div class="weui-header-fixed-top">
        <div class="weui-header weui-btn_primary"> 
            <div class="weui-header-left"><a id="btnBack" class="icon icon-109 f-white"></a></div>
            <div class="weui-header-title">就诊人详情</div>
            <div class="weui-header-right"></div>
        </div>
    </div>
    <div class="weui-cells weui-cells_form" style="border-top: 10px solid #EFF3F4;">
        <div class="weui-flex">
			请如实填写就诊人信息
		</div>   
        <span style="font-size:14px;margin-left:10px;color: #DC4815;">*请如实填写患者病历信息，带*号为必填。</span>
		
        <div class="weui-form">
			<div class="weui-form__control-area">
				<div class="weui-cells__group weui-cells__group_form">
					
					<div class="weui-cells weui-cells_form">
						<!-- 就诊人 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">就诊人<span class="f-red">*</span></label></div>
							<div class="weui-cell__bd">
								<input id="txt_patient_name" class="weui-input" placeholder="请输入就诊人姓名"/>
							</div>
						</div>
						<!-- 性别 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">性&nbsp;&nbsp;&nbsp;别<span class="f-red">*</span></label></div>
							<div class="weui-cell__bd choice" >
								 <label class="radio"><input type="radio" name="radio1" id="x12" value='0'><i></i>男</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								 <label class="radio"><input type="radio" name="radio1" id="x11" value='1'><i></i>女</label>
							</div>
						</div>
						<!-- 年龄 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">年&nbsp;&nbsp;&nbsp;龄<span class="f-red">*</span></label></div>
							<div class="weui-cell__bd">
								<input id="txt_patient_age" class="weui-input" placeholder="请输入就诊人的年龄"/>
							</div>
						</div>
						<!-- 手机 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">手&nbsp;&nbsp;&nbsp;机</label></div>
							<div class="weui-cell__bd">
								<input id="txt_patient_phone" class="weui-input" placeholder="请填写可输入的手机号" type="number" pattern="[0-9]*" />
							</div>
						</div>
						<!-- 体重(kg) -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">体&nbsp;&nbsp;&nbsp;重</label></div>
							<div class="weui-cell__bd">
									<input id="txt_patient_weight" class="weui-input" placeholder="请输入就诊人的体重(kg)" type="number" pattern="[0-9]*" />
							</div>
						</div>
						<!-- 职业 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">职&nbsp;&nbsp;&nbsp;业</label></div>
							<div class="weui-cell__bd">
								<input id="js_input" class="weui-input" placeholder="请输入就诊人的职业" type="number" pattern="[0-9]*" />
							</div>
						</div>
						<!-- 过敏史 -->
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd"><label class="weui-label">过敏史<span class="f-red">*</span></label></div>
							<div class="weui-cell__bd">
								<input id="ddl_drug_allergy" class="weui-input" placeholder="请填写就诊人是否有药物过敏史" type="number" pattern="[0-9]*" />
							</div>
						</div>
					</div>
					
				</div>
			</div>
			<br>
			<br>
			<div class="weui-form__opr-area">
				<a class="weui-btn weui-btn_primary weui-btn_disabled" href="javascript:" id="btnInquiry">确定</a>
			</div>
		</div>
	</div>
			

</body>
</html>